/**
 * 
 */
package com.hz.winnie.demands.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hz.winnie.demands.pojo.Demand;

/**
 * @description 需求DAO实现类
 * @author winnie
 * @date 2011-4-23
 * @version 1.0
 */
public class DemandsDaoImpl extends SqlMapClientDaoSupport implements
	DemandsDao {

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.dao.DemandsDao#countDemandsByCondition(com.hz.winnie
     * .demands.pojo.Demand)
     */
    @Override
    public int countDemandsByCondition(Demand demand) {
	int count = (Integer) getSqlMapClientTemplate().queryForObject(
		"demand.countDemandsByCondition", demand);
	return count;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.hz.winnie.demands.dao.DemandsDao#getDemandById(java.lang.String)
     */
    @Override
    public Demand getDemandById(String demandId) {
	Demand demand = (Demand) getSqlMapClientTemplate().queryForObject(
		"demand.getDemandById", demandId);
	return demand;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.dao.DemandsDao#listDemandsByCondition(com.hz.winnie
     * .demands.pojo.Demand)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<Demand> listDemandsByCondition(Demand demand) {
	List<Demand> list = (List<Demand>) getSqlMapClientTemplate()
		.queryForList("demand.listDemandsByCondition", demand);
	return list;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.dao.DemandsDao#update(com.hz.winnie.demands.pojo
     * .Demand)
     */
    @Override
    public void update(Demand demand) {
	getSqlMapClientTemplate().update("demand.update", demand);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.dao.DemandsDao#create(com.hz.winnie.demands.pojo
     * .Demand)
     */
    @Override
    public int create(Demand demand) {
	return (Integer) getSqlMapClientTemplate().insert("demand.create",
		demand);
    }

    @Override
    public void delete(String demandId) {
	getSqlMapClientTemplate().delete("demand.delete", demandId);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Demand> getDemandsByTitle(String title, String demandId) {
	Map map = new HashMap();
	map.put("title", title);
	map.put("demandId", demandId);
	return (List<Demand>) getSqlMapClientTemplate().queryForList(
		"demand.getDemandsByTitle", map);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.hz.winnie.demands.dao.DemandsDao#updateReaded(java.lang.String,
     * java.lang.String)
     */
    @SuppressWarnings("unchecked")
    @Override
    public void updateReaded(String demandId, String userId) {
	Map map = new HashMap();
	map.put("userId", userId);
	map.put("demandId", demandId);
	getSqlMapClientTemplate().update("demand.updateReaded", map);
    }

}
